package com.example.joketest;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.fragment.NavHostFragment;

import android.os.Bundle;
import android.view.MenuItem;

import com.example.lib_ui_common_sdk.AppBottomView;
import com.google.android.material.bottomnavigation.BottomNavigationView;

public class MainActivity extends AppCompatActivity {
    private AppBottomView appBottomView;
    private NavHostFragment fragment;
    private NavController controller;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        appBottomView = findViewById(R.id.app_bottom);
        fragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.host_fragment);
        controller = fragment.getNavController();
        new NavigationBuilder().create(this,getSupportFragmentManager(),controller,fragment.getId());
        appBottomView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                controller.navigate(item.getItemId());
                return true;
            }
        });
    }
}